package cn.com.bluemoon.daps.sync.core.sync.compare.sql;

import cn.com.bluemoon.daps.model.entity.DapDataModelTable;
import cn.com.bluemoon.daps.sync.base.BmScript;
import cn.com.bluemoon.daps.sync.base.ModifyType;
import cn.com.bluemoon.daps.sync.base.SqlCompareResult;
import cn.com.bluemoon.daps.sync.core.sync.GlobalConfig;
import cn.com.bluemoon.daps.sync.core.sync.Tuple2;
import cn.com.bluemoon.daps.sync.core.sync.compare.PartitionComparator;

import java.util.List;

/**
 * @author Jarod.Kong
 * @date 2021/6/3 14:30
 */
public class SqlPartitionComparator extends PartitionComparator<SqlCompareResult> {
    public SqlPartitionComparator(GlobalConfig globalConfig, Tuple2<DapDataModelTable> tableTuple2) {
        super(globalConfig, tableTuple2);
    }

    @Override
    public void change0(List<SqlCompareResult> collector) {
        super.change0(collector);
        BmScript sql = bmSql.changePartition(newTable, getOldT(), getNewT());
        collector.add(SqlCompareResult.builder()
                .modifyType(ModifyType.ALTER.partition())
                .script(sql)
                .build());
    }

    @Override
    public void drop0(List<SqlCompareResult> collector) {
        super.drop0(collector);
        BmScript sql = bmSql.dropPartition(oldTable, getOldT());
        collector.add(SqlCompareResult.builder()
                .modifyType(ModifyType.DROP.partition())
                .script(sql)
                .build());
    }

    @Override
    public void create0(List<SqlCompareResult> collector) {
        super.create0(collector);
        BmScript sql = bmSql.createPartition(newTable, getNewT());
        collector.add(SqlCompareResult.builder()
                .modifyType(ModifyType.CREATE.partition())
                .script(sql)
                .build());
    }
}
